import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { RoomEnvironmentApi } from '#/api/spa/room/environment';

import { z } from '#/adapter/form';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';

import { DICT_SPA_TYPE } from '#/utils/dictSpa';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'roomId',
      label: '房间ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入房间ID',
      },
    },
    {
      fieldName: 'monitorTime',
      label: '监控时间',
      rules: 'required',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'temperature',
      label: '温度(°C)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入温度(°C)',
      },
    },
    {
      fieldName: 'humidity',
      label: '湿度(%)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入湿度(%)',
      },
    },
    {
      fieldName: 'airQuality',
      label: '空气质量',
      component: 'Input',
      componentProps: {
        placeholder: '请输入空气质量',
      },
    },
    {
      fieldName: 'noiseLevel',
      label: '噪音水平(dB)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入噪音水平(dB)',
      },
    },
    {
      fieldName: 'lightingLevel',
      label: '光照水平(lux)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入光照水平(lux)',
      },
    },
    {
      fieldName: 'waterTemperature',
      label: '水温(°C)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入水温(°C)',
      },
    },
    {
      fieldName: 'waterQuality',
      label: '水质',
      component: 'Input',
      componentProps: {
        placeholder: '请输入水质',
      },
    },
    {
      fieldName: 'environmentMetrics',
      label: '环境指标JSON',
      component: 'Input',
      componentProps: {
        placeholder: '请输入环境指标JSON',
      },
    },
    {
      fieldName: 'scope',
      label: '权限范围',
      component: 'Input',
      componentProps: {
        placeholder: '请输入权限范围',
      },
    },
    {
      fieldName: 'scoperef',
      label: '权限引用',
      component: 'Input',
      componentProps: {
        placeholder: '请输入权限引用',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'roomId',
      label: '房间ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入房间ID',
      },
    },
    {
      fieldName: 'monitorTime',
      label: '监控时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'temperature',
      label: '温度(°C)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入温度(°C)',
      },
    },
    {
      fieldName: 'humidity',
      label: '湿度(%)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入湿度(%)',
      },
    },
    {
      fieldName: 'airQuality',
      label: '空气质量',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入空气质量',
      },
    },
    {
      fieldName: 'noiseLevel',
      label: '噪音水平(dB)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入噪音水平(dB)',
      },
    },
    {
      fieldName: 'lightingLevel',
      label: '光照水平(lux)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入光照水平(lux)',
      },
    },
    {
      fieldName: 'waterTemperature',
      label: '水温(°C)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入水温(°C)',
      },
    },
    {
      fieldName: 'waterQuality',
      label: '水质',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入水质',
      },
    },
    {
      fieldName: 'environmentMetrics',
      label: '环境指标JSON',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入环境指标JSON',
      },
    },
    {
      fieldName: 'scope',
      label: '权限范围',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入权限范围',
      },
    },
    {
      fieldName: 'scoperef',
      label: '权限引用',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入权限引用',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<RoomEnvironmentApi.RoomEnvironment>['columns'] {
  return [
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'roomId',
      title: '房间ID',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'monitorTime',
      title: '监控时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'temperature',
      title: '温度(°C)',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'humidity',
      title: '湿度(%)',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'airQuality',
      title: '空气质量',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'noiseLevel',
      title: '噪音水平(dB)',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'lightingLevel',
      title: '光照水平(lux)',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'waterTemperature',
      title: '水温(°C)',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'waterQuality',
      title: '水质',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'environmentMetrics',
      title: '环境指标JSON',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'scope',
      title: '权限范围',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'scoperef',
      title: '权限引用',
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_SPA_TYPE.HandCardStatus },
      },
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}

// ==================== 子表（SPA房间环境监控） ====================

/** 新增/修改的表单 */
export function useRoomEnvironmentFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'monitorTime',
      label: '监控时间',
      rules: 'required',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'temperature',
      label: '温度(°C)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入温度(°C)',
      },
    },
    {
      fieldName: 'humidity',
      label: '湿度(%)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入湿度(%)',
      },
    },
    {
      fieldName: 'airQuality',
      label: '空气质量',
      component: 'Input',
      componentProps: {
        placeholder: '请输入空气质量',
      },
    },
    {
      fieldName: 'noiseLevel',
      label: '噪音水平(dB)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入噪音水平(dB)',
      },
    },
    {
      fieldName: 'lightingLevel',
      label: '光照水平(lux)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入光照水平(lux)',
      },
    },
    {
      fieldName: 'waterTemperature',
      label: '水温(°C)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入水温(°C)',
      },
    },
    {
      fieldName: 'waterQuality',
      label: '水质',
      component: 'Input',
      componentProps: {
        placeholder: '请输入水质',
      },
    },
    {
      fieldName: 'environmentMetrics',
      label: '环境指标JSON',
      component: 'Input',
      componentProps: {
        placeholder: '请输入环境指标JSON',
      },
    },
    {
      fieldName: 'scope',
      label: '权限范围',
      component: 'Input',
      componentProps: {
        placeholder: '请输入权限范围',
      },
    },
    {
      fieldName: 'scoperef',
      label: '权限引用',
      component: 'Input',
      componentProps: {
        placeholder: '请输入权限引用',
      },
    },
    {
      fieldName: 'storeId',
      label: '门店ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入门店ID',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useRoomEnvironmentGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'roomId',
      label: '房间ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入房间ID',
      },
    },
    {
      fieldName: 'monitorTime',
      label: '监控时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'temperature',
      label: '温度(°C)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入温度(°C)',
      },
    },
    {
      fieldName: 'humidity',
      label: '湿度(%)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入湿度(%)',
      },
    },
    {
      fieldName: 'airQuality',
      label: '空气质量',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入空气质量',
      },
    },
    {
      fieldName: 'noiseLevel',
      label: '噪音水平(dB)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入噪音水平(dB)',
      },
    },
    {
      fieldName: 'lightingLevel',
      label: '光照水平(lux)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入光照水平(lux)',
      },
    },
    {
      fieldName: 'waterTemperature',
      label: '水温(°C)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入水温(°C)',
      },
    },
    {
      fieldName: 'waterQuality',
      label: '水质',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入水质',
      },
    },
    {
      fieldName: 'environmentMetrics',
      label: '环境指标JSON',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入环境指标JSON',
      },
    },
    {
      fieldName: 'scope',
      label: '权限范围',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入权限范围',
      },
    },
    {
      fieldName: 'scoperef',
      label: '权限引用',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入权限引用',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'storeId',
      label: '门店ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入门店ID',
      },
    },
  ];
}

/** 列表的字段 */
export function useRoomEnvironmentGridColumns(): VxeTableGridOptions<RoomApi.RoomEnvironment>['columns'] {
  return [
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,
    },
    {
      field: 'roomId',
      title: '房间ID',
      minWidth: 120,
    },
    {
      field: 'monitorTime',
      title: '监控时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'temperature',
      title: '温度(°C)',
      minWidth: 120,
    },
    {
      field: 'humidity',
      title: '湿度(%)',
      minWidth: 120,
    },
    {
      field: 'airQuality',
      title: '空气质量',
      minWidth: 120,
    },
    {
      field: 'noiseLevel',
      title: '噪音水平(dB)',
      minWidth: 120,
    },
    {
      field: 'lightingLevel',
      title: '光照水平(lux)',
      minWidth: 120,
    },
    {
      field: 'waterTemperature',
      title: '水温(°C)',
      minWidth: 120,
    },
    {
      field: 'waterQuality',
      title: '水质',
      minWidth: 120,
    },
    {
      field: 'environmentMetrics',
      title: '环境指标JSON',
      minWidth: 120,
    },
    {
      field: 'scope',
      title: '权限范围',
      minWidth: 120,
    },
    {
      field: 'scoperef',
      title: '权限引用',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      field: 'storeId',
      title: '门店ID',
      minWidth: 120,
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
